// 引入Strophe方法
var Strophejs = require("strophe.js");
var Strophe = Strophejs.Strophe;

// 给Strophe.Connection 添加方法
Strophe.Connection.prototype.setJid = jid => {
  Strophe.Connection.jid = jid;
  Strophe.Connection.authzid = Strophe.getBareJidFromJid(
    Strophe.Connection.jid
  );
  Strophe.Connection.authcid = Strophe.getNodeFromJid(Strophe.Connection.jid);
};

Strophe.Connection.prototype.getJid = () => {
  return Strophe.Connection.jid;
};

window.Strophe = Strophe;

const WebIM = require("easemob-websdk");

//配置文件参考环信demo
let config = {
  xmppURL: "im-api.easemob.com",
  apiURL:
    (location.protocol === "https:" ? "https:" : "http:") + "//a1.easemob.com",
  appkey: "1104161117115710#110",
  https: false,
  isMultiLoginSessions: true,
  isAutoLogin: true,
  isWindowSDK: false,
  isSandBox: false,
  isDebug: false,
  autoReconnectNumMax: 2,
  autoReconnectInterval: 2,
  // isWebRTC: (/Firefox/.test(navigator.userAgent) || /WebKit/.test(navigator.userAgent)) && /^https\:$/.test(window.location.protocol),
  heartBeatWait: 4500,
  isHttpDNS: false,
  msgStatus: true,
  delivery: true,
  read: true,
  saveLocal: false,
  encrypt: {
    type: "none"
  }
};

//初始化配置
WebIM.config = config;
const conn = () => {
  return new WebIM.connection({
    isMultiLoginSessions: WebIM.config.isMultiLoginSessions,
    https: WebIM.config.https,
    url: WebIM.config.xmppURL,
    isAutoLogin: true,
    heartBeatWait: WebIM.config.heartBeatWait,
    autoReconnectNumMax: WebIM.config.autoReconnectNumMax,
    autoReconnectInterval: WebIM.config.autoReconnectInterval,
    apiUrl: WebIM.config.apiURL
  });
};

export default {
  conn,
  WebIM
};
